﻿//https://leetcode.cn/problems/non-decreasing-subsequences/?envType=problem-list-v2&envId=hash-table

class Solution {
    vector<vector<int>> ret;
    vector<int> temp;
    int hash[201];
    bool vist[16];
public:
    bool IsFirt(vector<int>& temp)
    {
        //第一个答案不需要去重
        if (ret.size() == 0)
            return true;

        int count = 0;
        for (auto& e : ret)
        {
            if (temp.size() != e.size())
            {
                count++;
                continue;
            }

            for (int i = 0; i < e.size(); i++)
            {
                //如果有一个不一样的元素，就是不重复的答案
                if (e[i] != temp[i])
                {
                    count++;
                    break;
                }
            }
        }
        if (count == ret.size())
            return true;
        else
            return false;
    }
    vector<vector<int>> findSubsequences(vector<int>& nums)
    {
        int n = nums.size();
        for (int i = 0; i < n; i++)
        {
            temp.clear();
            dfs(nums, i, n);
            vist[i] = false;
        }
        return ret;
    }
    void dfs(vector<int>& nums, int pos, int n)
    {
        if (pos == n)
        {
            return;
        }

        temp.push_back(nums[pos]);
        vist[pos] = true;

        if (temp.size() > 1 && IsFirt(temp))
        {
            ret.push_back(temp);
        }

        for (int i = pos + 1; i < n; i++)
        {
            if (!vist[i] && nums[i] >= nums[pos])
            {
                dfs(nums, i, n);
                vist[i] = false;
                temp.pop_back();
            }
        }
    }
};